package com.ysb.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class PropertyConfig {
	
	private Properties prop;
	
	public PropertyConfig(String fileName, String charset) throws IOException {
		prop = new Properties();
		String path = PropertyConfig.class.getResource("/"+fileName+".property").getPath();
		prop.load(new InputStreamReader(new FileInputStream(path), charset));  
	}
	
	public String get(String name, String def) {
		String str = prop.getProperty(name);
		if(str == null) {
			return def;
		}
		return str;
	}
	
	public int getInt(String name, int def) {
		return StringUtil.convertInt(prop.getProperty(name), def);
	}
	
	
	public static void main(String ...args) throws IOException {
		PropertyConfig config = new PropertyConfig("wechat", "utf-8");
		System.out.println(config.get("token", ""));
		System.out.println(config.get("app", "default"));
	}
}
